package com.ant.backstage.config.filter;

import com.ant.backstage.facade.ApiReturn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author zhangyu
 * @Description
 * @Date 18:08 2022/1/14
 * @Param   请求的前置过滤器 实现的是tomcat的过滤器
 * @return
 **/
@Component
@Order(1)
public class PrefilterFilter implements Filter {

    private static final Logger logger = LoggerFactory.getLogger(PrefilterFilter.class);

    private static final ApiReturn notAuthorized = new ApiReturn();


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //开始
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 请求前置 过滤
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        resp.setCharacterEncoding("utf-8");
        String uri = req.getRequestURI();

        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
